//
//  MyBidJobDetailHistoryTableViewCell.swift
//  ezyform
//
//  Created by MoennigQ on 13/12/18.
//  Copyright © 2018 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import SnapKit
class ServcieDetailHistoryTableViewCell: TableViewCell {
    //tip image
    var tipImageView: UIImageView!
    var tipImageSizeConstant: Constraint!
    //contentView
    var backView: CustomBackView!
    //operator name
    var operNameLabel: BaseLabel!
    //operate date
    var operDateLabel: BaseLabel!
    //job status
    var jobStatusLabel: BaseLabel!
    //not title label
    var noteTitleLabel: BaseLabel!
    //note
    var noteLabel: BaseLabel!
    //last color
    let historyCellColor = UIColor(red: 0.52, green: 0.52, blue: 0.52,alpha:1)
    let lastCellColor = UIColor(red: 0.15, green: 0.13, blue: 0.14,alpha:1)
    var tipImageViewSizeConstraint: Constraint?
    var tipImageViewLeftConstraint: Constraint?
    override func setUpviews(){
        self.selectionStyle = .none
        //1.background color
        self.backgroundColor = UIColor(hexStr: Constant.TransparentColorHexStr)
        self.contentView.backgroundColor = UIColor(hexStr: Constant.TransparentColorHexStr)
        
        //2.tip image view
        tipImageView = UIImageView()
        tipImageView.contentMode = .center
        self.contentView.addSubview(tipImageView)
        tipImageView.snp.makeConstraints { (make) in
            make.top.equalTo(4)
            self.tipImageViewLeftConstraint = make.left.equalTo(20).constraint
            self.tipImageViewSizeConstraint = make.width.height.equalTo(24).constraint
        }
        //3.portrait line view
        let lineView = View(hexStr: "#292D321A")
        self.contentView.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.top.equalTo(tipImageView.snp.bottom).offset(8)
            make.bottom.equalTo(-8)
            make.width.equalTo(1)
            make.centerX.equalTo(tipImageView)
        }
        //
        backView = CustomBackView()
        self.contentView.addSubview(backView)
        backView.snp.makeConstraints { make in
            make.left.equalTo(tipImageView.snp.right).offset(12)
            make.top.equalToSuperview()
            make.right.equalTo(-20)
            make.height.greaterThanOrEqualTo(0)
            make.bottom.equalTo(-20)
        }
        //4.name label
        operNameLabel = ContentLabel(R.font.interSemiBold(size: 16))
        operNameLabel.textAlignment = .left
        operNameLabel.numberOfLines = 0
        backView.addSubview(operNameLabel)
        operNameLabel.snp.makeConstraints { (make) in
            make.left.top.equalTo(16)
            make.height.width.greaterThanOrEqualTo(0)
        }
        
        //4.oper date label
        operDateLabel = ContentLabel(R.font.interMedium(size: 13))
        operDateLabel.textAlignment = .left
        backView.addSubview(operDateLabel)
        operDateLabel.snp.makeConstraints { (make) in
            make.top.equalTo(operNameLabel.snp.bottom).offset(8)
            make.left.equalTo(operNameLabel)
            make.height.width.greaterThanOrEqualTo(0)
        }
    
        //5.job status label
        jobStatusLabel = ContentLabel(R.font.interMedium(size: 16))
        jobStatusLabel.numberOfLines = 0
        jobStatusLabel.textAlignment = .left
        backView.addSubview(jobStatusLabel)
        jobStatusLabel.snp.makeConstraints { (make) in
            make.top.equalTo(operDateLabel.snp.bottom).offset(18)
            make.left.equalTo(operDateLabel)
            make.right.equalTo(-16)
            make.bottom.equalTo(-16)
        }
    }
    func setData(_ historyModel: ServiceDetailHistoryModel, firstRowFlag: Bool){
        
        operNameLabel.text = historyModel.operator_name
        operDateLabel.text = historyModel.action_time

        var jobStatusOrUnqualifiedReason: String = historyModel.action
        if historyModel.action == "Unqualified" {
            jobStatusOrUnqualifiedReason = historyModel.action + ", " + historyModel.details
        }
        
        jobStatusLabel.text = jobStatusOrUnqualifiedReason
        
        if firstRowFlag {
            backView.backgroundColor = UIColor(hexStr: Constant.ThemeColorHexStr)
            operNameLabel.textColor = .white
            operDateLabel.textColor = UIColor(hexStr: "#FFFFFFB2")
            jobStatusLabel.textColor = .white
            tipImageView.image = UIImage(named: "service_mybidjob_detail_tabhistory_tipnow")
            self.tipImageViewSizeConstraint?.update(offset: 24)
            self.tipImageViewLeftConstraint?.update(offset: 20)
        }else{
            backView.backgroundColor = .white
            operNameLabel.textColor = UIColor(hexStr: "#292D3299")
            operDateLabel.textColor = UIColor(hexStr: "#292D3299")
            jobStatusLabel.textColor = UIColor(hexStr: "#292D3299")
            tipImageView.image = UIImage(named: "service_mybidjob_detail_tabhistory_tippast")
            self.tipImageViewSizeConstraint?.update(offset: 12)
            self.tipImageViewLeftConstraint?.update(offset: 26)
        }
        
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }

}
